package com.haoshuang.zhouzhoubang.ui.page.mine

import com.haoshuang.zhouzhoubang.model.api.ApiRepo
import com.haoshuang.zhouzhoubang.model.bean.CooperationTimeBean
import com.haoshuang.zhouzhoubang.model.bean.HomeDataBean
import com.haoshuang.zhouzhoubang.model.bean.UserBean
import com.mufeng.libs.base.BaseViewModel
import com.mufeng.libs.net.ResponseBean
import com.mufeng.libs.net.netRequest
import com.mufeng.libs.state.StateData
import com.mufeng.libs.state.StatefulMutableLiveData

class MineViewModel : BaseViewModel() {

    /**
     * 获取门店个人信息
     */
    val getStoreUserInfoData = StatefulMutableLiveData<ResponseBean<UserBean>>()
    fun getStoreUserInfo() = netRequest {
        start { getStoreUserInfoData.value = StateData.Loading }
        request { ApiRepo.getStoreInfo() }
        success { getStoreUserInfoData.value = StateData.Success(it) }
        error { code, msg ->
            getStoreUserInfoData.value = StateData.Error(code, msg)
        }
    }
    /**
     * 获取首页数据
     */
    val getHomeDataData = StatefulMutableLiveData<ResponseBean<HomeDataBean>>()
    fun getHomeData() = netRequest {
        start { getHomeDataData.value = StateData.Loading }
        request { ApiRepo.getHomeData() }
        success { getHomeDataData.value = StateData.Success(it) }
        error { code, msg ->
            getHomeDataData.value = StateData.Error(code, msg)
        }
    }
    /**
     * 获取合作期限
     */
    val getCooperationPeriodData =
        StatefulMutableLiveData<ResponseBean<MutableList<CooperationTimeBean>>>()

    fun getCooperationPeriod(city: String?) = netRequest {
        start { getCooperationPeriodData.value = StateData.Loading }
        request { ApiRepo.getCooperationPeriod(city) }
        success { getCooperationPeriodData.value = StateData.Success(it) }
        error { code, msg ->
            getCooperationPeriodData.value = StateData.Error(code, msg)
        }
    }
}